<!DOCTYPE html>
<html>
<head>
    <title>备件报废关联设备信息</title>
    #parse("sys/header.html")
</head>
<body>
<div id="rrapp" v-cloak>
    <div>
        <Row :gutter="16" style="padding: 5px 0px 0px 20px">
            <div class="search-group">
                <i-col span="4">
                    <i-input v-model="q.devProductName" @on-enter="query" placeholder="生产线名称"></i-input>
                </i-col>
                <i-col span="4">
                    <i-input v-model="q.devProceName" @on-enter="query" placeholder="工序名称"></i-input>
                </i-col>
                <i-col span="4">
                    <i-input v-model="q.devName" @on-enter="query" placeholder="设备名称"></i-input>
                </i-col>
                <i-button @click="query">查询</i-button>
                <i-button @click="reloadSearch">重置</i-button>
            </div>
        </Row>
        <div style="height: 85vh;width:28%;overflow:auto;float:left;padding:10px;">
            <!-- 选择部门 -->
            <div id="deptLayer">
                <ul id="deptTree" class="ztree"></ul>
            </div>
        </div>
        <div id="container" style="width:70%;height:500px;overflow:auto;float:left;margin: 10px;">
        <table id="jqGrid"></table>
        </div>
    </div>
</div>

<script>
    $(function () {
        // 默认加载部门树
        vm.getDept();
    });
    var setting = {
        data: {
            simpleData: {
                enable: true,
                idKey: "deptId",
                pIdKey: "parentId",
                rootPId: -1
            },
            key: {
                url: "nourl"
            }
        },
        callback: {
            beforeCheck: true
        }
    };
    //部门树
    var deptSetting = {
        data: {
            simpleData: {
                enable: true,
                idKey: "deptId",
                pIdKey: "parentId",
                rootPId: -1
            },
            key: {
                url: "nourl",
                name:"complexName"
            }
        },
        callback: {
            beforeCheck: true,
            beforeClick: outTreeCheck
        }
    };

    function outTreeCheck(e, treeObj, treeNode) {
        vm.q.deptCode = treeObj.deptId;
        vm.query();
    }
    $(function () {
            $("#jqGrid").Grid({
                url: '../deviceinfo/list',
                sortname: 'CREATE_DATE',
                sortorder: 'DESC',
                colModel: [
                    {label: '设备编码', name: 'devCode', index: 'DEV_CODE', width: 60},
                    {label: '设备名称', name: 'devName', index: 'DEV_NAME', width: 80},
                    {label: '生产线名称', name: 'devProductName', index: 'DEV_PRODUC_NAMET', width: 100},
                    {label: '工序名称', name: 'devProceName', index: 'DEV_PROCE_NAME', width: 80},
                    {label: 'id', name: 'id', index: 'ID', key: true, hidden: true}
                ]
            });
            vm.getTreeList();
    });
    let vm = new Vue({
        el: '#rrapp',
        data: {
            showList: true,
            q: {
                devProductCode: '',
                deptCode:'',
                devName: '',
                devProductName:'',
                devProceName:''
            },
        },
        methods: {
            query: function () {
                vm.reload();
            },
            reload: function (event) {
                vm.showList = true;
                var page = $("#jqGrid").jqGrid('getGridParam', 'page');
                $("#jqGrid").jqGrid('setGridParam', {
                    search: true,
                    postData:vm.q,
                    page: page
                }).trigger("reloadGrid");
            },
           reloadSearch: function () {
                vm.q = {
                    devProductName:'',
                    devProceName:'',
                    devName: '',
                    deptCode:''
                };
                // 取消设备组织树选中
                ztree.cancelSelectedNode();
                vm.reload();
            },
            getDept: function () {
                //加载部门树
                Ajax.request({
                    url: '../sys/user/treeDeptBySCX',
                    async: false,
                    successCallback: function (r) {
                        ztree = $.fn.zTree.init($("#deptTree"), deptSetting, r.list);
                        ztree.expandAll(true);
                        var node = ztree.getNodeByParam("deptId", '01');
                        if (node != null) {
                            vm.curDeptName = node.name;
                            vm.q.curDeptId = node.deptId;
                            ztree.selectNode(node);
                        }
                        // 执行查询
                        vm.query();
                    }
                });
            },
            getTreeList: function () {
                Ajax.request({
                    // url: '../sys/user/treeDeptByType/DT_CJKSCX',
                    url: '../sys/user/treeDeptBySCX',
                    async: false,
                    successCallback: function (r) {
                        vm.treeList = r.list;
                    }
                });
            },
        }
    });
    var getDeviceInfo = function () {
        let result = getSelectedRowData("#jqGrid");
        var id = result.id;
        console.log(result);
        if (id == null) {
            return false;
        } else {
            return result;
        }
    }
</script>
</body>
</html>
